package com.landinfo.service.impl;

import com.landinfo.service.SpecialMapServiceManageService;
import com.landinfo.domain.SpecialMapServiceManage;
import com.landinfo.repository.SpecialMapServiceManageRepository;
import com.landinfo.service.dto.SpecialMapServiceManageDTO;
import com.landinfo.service.mapper.SpecialMapServiceManageMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Service Implementation for managing SpecialMapServiceManage.
 */
@Service
@Transactional
public class SpecialMapServiceManageServiceImpl implements SpecialMapServiceManageService{

    private final Logger log = LoggerFactory.getLogger(SpecialMapServiceManageServiceImpl.class);

    private final SpecialMapServiceManageRepository specialMapServiceManageRepository;

    private final SpecialMapServiceManageMapper specialMapServiceManageMapper;

    public SpecialMapServiceManageServiceImpl(SpecialMapServiceManageRepository specialMapServiceManageRepository, SpecialMapServiceManageMapper specialMapServiceManageMapper) {
        this.specialMapServiceManageRepository = specialMapServiceManageRepository;
        this.specialMapServiceManageMapper = specialMapServiceManageMapper;
    }

    /**
     * Save a specialMapServiceManage.
     *
     * @param specialMapServiceManageDTO the entity to save
     * @return the persisted entity
     */
    @Override
    public SpecialMapServiceManageDTO save(SpecialMapServiceManageDTO specialMapServiceManageDTO) {
        log.debug("Request to save SpecialMapServiceManage : {}", specialMapServiceManageDTO);
        SpecialMapServiceManage specialMapServiceManage = specialMapServiceManageMapper.toEntity(specialMapServiceManageDTO);
        specialMapServiceManage = specialMapServiceManageRepository.save(specialMapServiceManage);
        return specialMapServiceManageMapper.toDto(specialMapServiceManage);
    }

    /**
     *  Get all the specialMapServiceManages.
     *
     *  @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public List<SpecialMapServiceManageDTO> findAll() {
        log.debug("Request to get all SpecialMapServiceManages");
        return specialMapServiceManageRepository.findAll().stream()
            .map(specialMapServiceManageMapper::toDto)
            .collect(Collectors.toCollection(LinkedList::new));
    }

    /**
     *  获取所有生效的专题图层信息
     *
     *  @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public List<SpecialMapServiceManageDTO> findAllByEnable(boolean enable) {
        log.debug("Request to get all SpecialMapServiceManages by enable");
        return specialMapServiceManageRepository.findAllByEnable(enable).stream()
            .map(specialMapServiceManageMapper::toDto)
            .collect(Collectors.toCollection(LinkedList::new));
    }

    /**
     *  通过父级Id获取子级所有数据
     *
     *  @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public List<SpecialMapServiceManageDTO> getChildrenByParentId(String parentId) {
        log.debug("Request to get all SpecialMapServiceManages by parentId");
        return specialMapServiceManageRepository.findAllByParentId(parentId).stream()
            .map(specialMapServiceManageMapper::toDto)
            .collect(Collectors.toCollection(LinkedList::new));
    }

    /**
     *  根据模板类型获取数据
     *
     *  @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public List<SpecialMapServiceManageDTO> getByTemplateType(String type) {
        log.debug("Request to get all SpecialMapServiceManages by type");
        return specialMapServiceManageRepository.findAllByTemplateType(type).stream()
            .map(specialMapServiceManageMapper::toDto)
            .collect(Collectors.toCollection(LinkedList::new));
    }

    /**
     *  Get one specialMapServiceManage by id.
     *
     *  @param id the id of the entity
     *  @return the entity
     */
    @Override
    @Transactional(readOnly = true)
    public SpecialMapServiceManageDTO findOne(String id) {
        log.debug("Request to get SpecialMapServiceManage : {}", id);
        SpecialMapServiceManage specialMapServiceManage = specialMapServiceManageRepository.findOneById(id);
        return specialMapServiceManageMapper.toDto(specialMapServiceManage);
    }

    /**
     *  根据图层组名获取数据
     *
     *  @param groupName the specialMapGroupName of the entity
     *  @return the entity
     */
    @Override
    @Transactional(readOnly = true)
    public SpecialMapServiceManageDTO getByGroupName(String groupName) {
        log.debug("Request to get SpecialMapServiceManage : {}", groupName);
        SpecialMapServiceManage specialMapServiceManage = specialMapServiceManageRepository.findOneBySpecialMapGroupName(groupName);
        return specialMapServiceManageMapper.toDto(specialMapServiceManage);
    }

    /**
     *  Delete the  specialMapServiceManage by id.
     *
     *  @param id the id of the entity
     */
    @Override
    public void delete(String id) {
        log.debug("Request to delete SpecialMapServiceManage : {}", id);
        specialMapServiceManageRepository.deleteById(id);
    }
}
